package org.zebra.tenant;

import cn.hutool.core.util.StrUtil;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * 租户id获取器
 *
 * @author zhanghongbin
 */
public class TenantIdAcquirer {

    /**
     * header 中获得租户id
     *
     * @param request 请求
     * @return 值
     */
    public <T extends Serializable> T getTenantId(HttpServletRequest request) {
        String tenantId = request.getHeader(TenantHelper.HEADER_TENANT_ID);
        if (TenantHelper.getIdType().equals("Integer") && !StrUtil.isEmpty(tenantId)) {
            return (T) Integer.valueOf(tenantId);
        } else if ("".equals(tenantId)) {
            tenantId = null;
        }
        return (T) tenantId;
    }
}
